#include <opencv2/opencv.hpp>
#include <iostream>
#include "object_distance.h"
#include "camera_parameters.h"
#include "record_time.h"

using namespace std;
using namespace cv;


int main()
{


#ifndef _DEBUG
	for (int i = 0; i < 4; i++)
	{
		START_RECORD_TIME("findCycleEx");
		string path = "../image/cycle_complex" + to_string(i) + ".jpg";
		Mat img = imread(path, IMREAD_ANYCOLOR | IMREAD_ANYDEPTH);
		std::vector<cv::Point> cyclePoints;
		findCycleEx(img, cyclePoints);
		END_RECORD_TIME("findCycleEx");
	}
#endif

#ifndef NDEBUG
	string path = "../image/cycle_big.jpg";
	Mat img = imread(path, IMREAD_ANYCOLOR | IMREAD_ANYDEPTH);

	CameraParameters cameraParameters(20, 5, 5);

	double objectRadius = 100.0;

	VideoCapture capture(0);

	while (true)
	{

		capture >> img;

		double dis1, dis2;

		//START_RECORD_TIME("distance")
		dis1 = objectDistance(img, objectRadius, cameraParameters, DISTANCE_BY_AREA);
		dis2 = objectDistance(img, objectRadius, cameraParameters, DISTANCE_BY_LENGTH);
		//END_RECORD_TIME("distance")

		if (dis1 > 0 && dis2 > 0)
			cout << "distance = " << dis1 << " " << dis2 << endl;
		else
			cout << "no cycle" << endl;

		imshow("origin image", img);

		if ('q' == waitKey(10))
			break;
	}

	capture.release();

#endif

	return 0;
}

